const validMap = {
	empty: function (str, trigger) {
		//非空
		return { name: 'empty', required: true, validator: validOrder.validEmpty, message: `${str}为必填项,值不能为空` };
	},
	email: function (str, trigger) {
		//邮件
		return { name: 'email', validator: validOrder.validEmail, message: `${str}请输入正确的邮件格式`, trigger };
	},
	number: function (str, trigger) {
		//数字
		return { name: 'number', validator: validOrder.validNumber, message: `${str}必须为数字格式`, trigger };
	},
	integer: function (str, trigger) {
		//整数
		return { name: 'integer', validator: validOrder.validInteger, message: `${str}要求为整数格式`, trigger };
	},
	pinteger: function (str, trigger) {
		//正整数
		return { name: 'pinteger', validator: validOrder.validPinteger, message: `${str}要求为正整数格式`, trigger };
	},
	phone: function (str, trigger) {
		//电话(固话)网上自己找的
		return { name: 'phone', validator: validOrder.validPhone, message: `${str}格式错误,请填写正确号码`, trigger };
	},
	mobile: function (str, trigger) {
		//手机号码
		return { name: 'mobile', validator: validOrder.validMobile, message: `${str}格式错误,请填写正确手机号码`, trigger };
	},
	custMobile: function (str, trigger) {
		//手机号码
		return { name: 'custMobile', validator: validOrder.validCustMobile, message: `${str}格式错误,请填写正确手机号码`, trigger };
	},
	double: function (str, trigger) {
		//小数
		return { name: 'double', validator: validOrder.validDouble, message: `${str}要求为小数格式`, trigger };
	},
	english: function (str, trigger) {
		//英文
		return { name: 'english', validator: validOrder.validEnglish, message: `${str}要求为纯英文字母`, trigger };
	},
	chinese: function (str, trigger) {
		//中文
		return { name: 'chinese', validator: validOrder.validChinese, message: `${str}请填写中文格式`, trigger };
	},
	qq: function (str, trigger) {
		//QQ号码
		return { name: 'qq', validator: validOrder.validQQ, message: `${str}请填写正确的QQ号码`, trigger };
	},
	zip: function (str, trigger) {
		//邮编
		return { name: 'zip', validator: validOrder.validZip, message: `${str}请填写正确的邮编格式`, trigger };
	},
	IPTlength: function (str, trigger) {
		//长度
		return { name: 'IPTlength', validator: validOrder.validIPTlength, message: `${str}字数请在20字以内`, trigger };
	},
	iPAddreess: function (str, trigger) {
		//IP地址校验
		return { name: 'iPAddreess', validator: validOrder.validIPAddreess, message: `${str}IP地址输入不正确`, trigger };
	},
	negaNumber: function (str, trigger) {
		//非负数
		return { name: 'iPAddreess', validator: validOrder.validNegaNumber, message: `${str}值要求为非负数`, trigger };
	},
	exceedTime: function (str, trigger) {
		//日期不能小于当天时间
		return { name: 'exceedTime', validator: validOrder.validExceedTime, message: `${str}必须大于等于当前日期` };
	},
};
export default validMap;

export const validOrder = {
	validEmpty: function (rule, value, callback) {
		if (value == '' || value == undefined || value == null) {
			return callback(new Error('${str}为必填项,值不能为空'))
		} else {
			if (value == 'http://' || value == 'https://') {//http为5g产品http-select插件提供
				return callback(new Error('${str}为必填项,值不能为空'))
			} else if (value == 'k' || value == 'M' || value == 'G') {//k,M,G为虚拟专网速率插件提供
				return callback(new Error('${str}为必填项,值不能为空'))
			} else {
				callback()
			}
		}
	},
	validEmail: function (rule, value, callback) {
		const reg = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}请输入正确的邮件格式'));
			} else {
				callback();

			}
		}
	},
	validNumber: function (rule, value, callback) {
		const reg = /^[0-9]*$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}必须为数字格式'));
			} else {
				callback();

			}
		}
	},
	validInteger: function (rule, value, callback) {
		const reg = /^[-\+]?\d+$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}要求为整数格式'));
			} else {
				callback();

			}
		}
	},
	validPinteger: function (rule, value, callback) {
		const reg = /^[1-9]{1}[\d]*$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}要求为正整数格式'));
			} else {
				callback();

			}
		}
	},
	validPhone: function (rule, value, callback) {
		const reg = /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}格式错误,请填写正确号码'));
			} else {
				callback();

			}
		}
	},
	validMobile: function (rule, value, callback) {
		const reg = /^((\(\d{3}\))|(\d{3}\-))?1[356789]\d{9}$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}格式错误,请填写正确手机号码'));
			} else {
				callback();

			}
		}
	},
	validCustMobile: function (rule, value, callback) {
		const reg = /^(13[0-9]|14[1457]|15[0-3,5-9]|16[6]|17[0145678]|18[0-9]|19[89])\d{8}$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}格式错误,请填写正确手机号码'));

			} else {
				callback();

			}
		}
	},
	validDouble: function (rule, value, callback) {
		const reg = /^[-]?(([1-9][\d]+)|((([1-9][\d]+)|0)(\.\d+)))$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}要求为小数格式'));

			} else {
				callback();

			}
		}
	},
	validEnglish: function (rule, value, callback) {
		const reg = /^[A-Za-z]+$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}要求为纯英文字母'));

			} else {
				callback();

			}
		}
	},
	validChinese: function (rule, value, callback) {
		const reg = /[\u4e00-\u9fa5]/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}请填写中文格式'));

			} else {
				callback();

			}
		}
	},
	validQQ: function (rule, value, callback) {
		const reg = /^[1-9]\d{4,8}$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}请填写正确的QQ号码'));

			} else {
				callback();

			}
		}
	},
	validZip: function (rule, value, callback) {
		const reg = /^[1-9]\d{5}$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}请填写正确的邮编格式'));

			} else {
				callback();

			}
		}
	},
	validIPTlength: function (rule, value, callback) {
		const reg = /^\d{1,20}$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}字数请在20字以内'));

			} else {
				callback();

			}
		}
	},
	validIPAddreess: function (rule, value, callback) {
		const reg = /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}IP地址输入不正确'));

			} else {
				callback();

			}
		}
	},
	validNegaNumber: function (rule, value, callback) {
		const reg = /^\d+(\.{0,1}\d+){0,1}$/;
		if (value == '' || value == undefined || value == null) {
			callback();
		} else {
			if ((!reg.test(value)) && value != '') {
				callback(new Error('${str}值要求为非负数'));

			} else {
				callback();

			}
		}
	},
	validExceedTime: function (rule, value, callback) {
		let nowDate = new Date();
		let year = nowDate.getFullYear();
		let month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
		let day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
		let dateStr = year + "-" + month + "-" + day + " 00:00:00";
		const now = new Date(dateStr).getTime() //当前-时间
		const _value = new Date(value).getTime() //页面传值-时间
		if (value == '' || _value < now) {
			return callback(new Error('${str}必须大于等于当前日期'))
		} else {
			callback()
		}
	},
}

